1 using UnityEngine;
2 using
System.Collections;
3
4
5 public
class RotationQuaternionTweenProperty : AbstractQuaternionTweenProperty
6 {
7     
private bool _useLocalRotation;
8     
public bool useLocalRotation { get { return _useLocalRotation; } }
9     
10     
11     
public RotationQuaternionTweenProperty( Quaternion endValue, bool isRelative = false, bool useLocalRotation = false ) : base( endValue, isRelative )
12     {
13         _useLocalRotation = useLocalRotation;
14     }
15     
16     
17     
#region Object overrides
18     
19     
public override int GetHashCode()
20     {
21         
return base.GetHashCode();
22     }
23     
24     
25     
public override bool Equals( object obj )
26     {
27         
// start with a base check and then compare if we are both using local values
28         
if( base.Equals( obj ) )
29             
return this._useLocalRotation == ((RotationQuaternionTweenProperty)obj)._useLocalRotation;
30
31         
return false;
32     }
33     
34     
#endregion
35     
36     
37     
public override void prepareForUse()
38     {
39         _target = _ownerTween.target
as Transform;
40         
41         _endValue = _originalEndValue;
42         
43         
// if this is a from tween we need to swap the start and end values
44         
if( _ownerTween.isFrom )
45         {
46             _startValue = _endValue;
47             
48             
if( _useLocalRotation )
49                 _endValue = _target.localRotation;
50             
else
51                 _endValue = _target.rotation;
52         }
53         
else
54         {
55             
if( _useLocalRotation )
56                 _startValue = _target.localRotation;
57             
else
58                 _startValue = _target.rotation;
59         }
60         
61         
base.prepareForUse();
62     }
63     
64     
65     
public override void tick( float totalElapsedTime )
66     {
67         
var easedTime = _easeFunction( totalElapsedTime, 0, 1, _ownerTween.duration );
68         Quaternion newOrientation = Quaternion.Slerp (_startValue, _endValue, easedTime);
69         
70         
if( _useLocalRotation )
71             _target.localRotation = newOrientation;
72         
else
73             _target.rotation = newOrientation;
74     }
75
76 }



Trò chơi Angry Birds trong UNITY Engine 31.662 lượt xem

Gõ tìm kiếm nhanh...